package com.binance.gateway.util;

import java.net.URI;
import java.net.URISyntaxException;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class URIUtil {

    /**
     * 格式化uri 若uri中包含 .. 都会转换成真正的路径
     * 
     * @param request
     * @return
     */
    public static String normalize(HttpServletRequest request) {
        if (request == null) {
            return StringUtils.EMPTY;
        }
        try {
            String uri = new URI(request.getRequestURI()).normalize().toString();
            return uri;
        } catch (URISyntaxException e) {
            log.warn("invalid uri={}", request.getRequestURI(), e);
        }
        return StringUtils.EMPTY;
    }
}
